set(BUILTIN_TEMPLATES
    builtins_declaration_gen.h.erb
    builtins_ids_gen.inl.erb
    builtins_initializers_gen.h.erb
    builtins_resolve_inlinable_gen.inl.erb
    builtins_inline_intrinsics_decls_gen.inl.erb
    builtins_inline_intrinsics_gen.inl.erb
)

set(INTRINSICS_YAML_PATH ${PANDA_BINARY_ROOT}/runtime/intrinsics.yaml)
set(INSTRUCTIONS_YAML_PATH ${PANDA_ROOT}/compiler/optimizer/ir/instructions.yaml)

file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/generated)
panda_gen(
    DATA
        ${INSTRUCTIONS_YAML_PATH}
        ${INTRINSICS_YAML_PATH}
        ${CMAKE_CURRENT_SOURCE_DIR}/templates/builtins.yaml
    API
        ${PANDA_ROOT}/compiler/optimizer/templates/instructions.rb
        ${PANDA_ROOT}/runtime/templates/intrinsics.rb
        ${CMAKE_CURRENT_SOURCE_DIR}/templates/builtins.rb
    TARGET_NAME ecma_builtins_gen
    TEMPLATES ${BUILTIN_TEMPLATES}
    REQUIRES
        ${PANDA_ROOT}/templates/common.rb
        ${PANDA_ROOT}/libpandabase/utils.rb
    SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/templates
    DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/generated
    EXTRA_DEPENDENCIES arkruntime_gen_intrinsics_yaml
)

add_dependencies(intrinsics_gen_arkruntime ecma_builtins_gen)
